<?php

require_once('StringLoadingStrategy/StringLoadingStrategyInterface.php');
require_once('AnalyzeStrategy/AnalyzeStrategyInterface.php');

class StringAnalizator {

    /**
     *
     * @var StringLoadingStrategyInterface
     */
    protected $stringLoadingStrategy = null;

    /**
     *
     * @var AnalyzeStrategyInterface
     */
    protected $analyzeStrategy = null;
    
    /**
     *
     * @var string
     */
    protected $string = null;

    public function __construct(StringLoadingStrategyInterface $stringLoadingStrategy = null, AnalyzeStrategyInterface $analyzeStrategy = null, $loadParam = null) {
        if ($stringLoadingStrategy === null) {
            throw new Exception('String loading strategy must be set');
        }

        if ($analyzeStrategy === null) {
            throw new Exception('Analyze strategy must be set');
        }

        $this->stringLoadingStrategy = $stringLoadingStrategy;
        $this->analyzeStrategy = $analyzeStrategy;
        
        if ($loadParam !== null) {
            $this->load($loadParam);
        }
    }
    
    /**
     *
     * @param mixed $loadParam 
     */
    public function load($loadParam) {
        $this->string = $this->stringLoadingStrategy->load($loadParam);
    }
    
    /**
     *
     * @return mixed
     */
    public function analyze() {
        return $this->analyzeStrategy->analyze($this->string);
    }
    
    /**
     *
     * @return string
     */
    public function getString() {
        return $this->string;
    }

}